package collection01;

import java.util.ArrayList;
import java.util.List;

public class ListDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);//[one, two, three, four, five]
        System.out.println("----------------------");

        String e = list.get(3);//获取下标3位置的元素
        System.out.println(e);//four

        for (int i=0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
        System.out.println("----------------------");

        list.set(2,"six");//将list中下标为2的元素设置为six ---- 常规操作
        System.out.println("list: "+list);
        System.out.println("----------------------");
        String old = list.set(3,"seven");//将list中下标为3的元素设置为seven, 同时返回被替换的元素
        System.out.println(old);
        System.out.println("list: "+list);
    }
}
